const jwt = require('jsonwebtoken');
const { secretKey } = require('../config/config')

//生成token
exports.create = function(user){
    const token = jwt.sign({ user }, secretKey, {
        expiresIn: 1000*60*60*24*120
      });
      return token
}

//验证token
exports.verifytoken = async function(token){
    return new Promise((resolve, reject) => {
		jwt.verify(token, secretKey, (error, result) => {
            if(error){
                reject(error)
            } else {
                resolve(result)
            }
		})
	})
}